//Provide utility functions, used by multiple pages

//Escape all HTML special symbols from given string.
function htmlEscape(str) {  
    var ret = str;  
    var regexp = /&/g;
    ret = ret.replace(regexp, "&amp;");
    regexp = /</g;
    ret = ret.replace(regexp, "&lt;");  
    regexp = />/g;  
    ret = ret.replace(regexp, "&gt;");
    regexp = /\"/g;
    ret = ret.replace(regexp, "&quot;");
    regexp = /\\/g;
    ret = ret.replace(regexp, "&#092;");
    return ret;  
}

//Take escaped HTML string and replace all escaped values with 
// their special meaning.
function htmlUnescape(str) {  
    var ret = str;  
    var regexp = /&amp;/g;
    ret = ret.replace(regexp, "&");
    regexp = /&lt;/g;
    ret = ret.replace(regexp, "<");  
    regexp = /&gt;/g;  
    ret = ret.replace(regexp, ">");
    regexp = /&quot;/g;
    ret = ret.replace(regexp, "\"");
    regexp = /&#092;/g;
    ret = ret.replace(regexp, "\\");
    return ret;  
} 